<html>
<head><meta charset="utf-8"><title>status of using the `AllocRef` trait  in generics · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html">status of using the `AllocRef` trait  in generics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195752688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/195752688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#195752688">(Apr 29 2020 at 18:42)</a>:</h4>
<p>I remember that previously we were held up on incorporating the <code>AllocRef</code> trait in <code>Box</code> and <code>Vec</code> generics because it was impossible to separate a nightly feature like that from stable. What is the status on this?</p>



<a name="195756671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/195756671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#195756671">(Apr 29 2020 at 19:13)</a>:</h4>
<p>No change that I know of.</p>



<a name="195756723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/195756723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#195756723">(Apr 29 2020 at 19:13)</a>:</h4>
<p>I think a first step would be to try a crater run to see if adding the parameters breaks any existing code.</p>



<a name="195759238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/195759238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#195759238">(Apr 29 2020 at 19:32)</a>:</h4>
<p>As long as we don't change return types this shouldn't be a problem, but a crater run is definitely required.</p>



<a name="196868790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196868790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196868790">(May 08 2020 at 08:15)</a>:</h4>
<p>What would be the next steps if <a href="https://github.com/rust-lang/rust/issues/71873" title="https://github.com/rust-lang/rust/issues/71873">#71873</a> passed the crater run?</p>



<a name="196869067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196869067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196869067">(May 08 2020 at 08:19)</a>:</h4>
<p>Even if we add a parameter to <code>Box</code> upstream, it would not be possible to construct it without <code>#![feature(allocator_api)]</code>. So is pushing something like <a href="https://github.com/rust-lang/rust/pull/71873/commits/133652486697a384bd653f5db8b758f3b462d30c" title="https://github.com/rust-lang/rust/pull/71873/commits/133652486697a384bd653f5db8b758f3b462d30c">the first commit</a> an option? Or should we add <code>liballoc::alloc::boxed</code> as temporary solution?</p>



<a name="196940797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196940797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196940797">(May 08 2020 at 19:36)</a>:</h4>
<p>Do you mean that it won't be possible to allocate using a custom <code>AllocRef</code> without <code>#![feature(allocator_api)]</code> or it won't be able to allocate <code>Box::new</code> at all - without that feature?</p>
<p>I don't understand what the "first commit" illustrates. Could you elaborate?</p>



<a name="196943946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196943946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196943946">(May 08 2020 at 20:03)</a>:</h4>
<p>The former: it's not possible to use a custom <code>AllocRef</code> without the feature flag, as every method returning <code>Self</code> is either only implemented on <code>Box&lt;T, Global&gt;</code> or is marked as unstable. Old methods like <code>Box::new</code> works as before (that's why the crater run is needed). However it's possible to name a <code>Box&lt;T, _&gt; = Box::new()</code> (<code>_</code> as wildcard which resolves to <code>Global</code>). If we are sure, the second parameter will be a thing, this is fine. </p>
<p>Currently <code>System</code> also implements <code>AllocRef</code> so one could write<br>
<code>let b: Option&lt;Box&lt;u32, System&gt;&gt; = None</code> on stable (However it should not be possible to construct it on stable). This could be solved by removing <code>AllocRef</code> from <code>System</code> for now, but it applied the same as above: If we are sure there will be a second parameter on <code>Box</code> and <code>System</code> will be valid there, this is fine. </p>
<p>The first commit in the PR only adds the allocator parameter to the collections and box-like structures without using it. On box and vec-like structures, the <code>AllocRef</code> instance is stored alongside the struct, for other types, a <code>PhantomData&lt;A&gt;</code> is added. This is basically to check type inference for defaulted generics.</p>



<a name="196945434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196945434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196945434">(May 08 2020 at 20:17)</a>:</h4>
<p><span class="user-mention" data-user-id="216785">@Tim Diekmann</span> Are you planning on pushing any more changes to that PR? If not then I'll update the crater run (which hasn't started yet, it's in the <a href="https://crater.rust-lang.org/" title="https://crater.rust-lang.org/">queue</a>) to point to the latest code you have so far.</p>



<a name="196949541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196949541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196949541">(May 08 2020 at 20:54)</a>:</h4>
<p>I think I'm done for now. The most important structs are changed (Box, Vec, String), i think those are the most used collection types used. Thank you!</p>



<a name="196949599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196949599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196949599">(May 08 2020 at 20:55)</a>:</h4>
<p>I'll double check the commits later or tomorrow, but I think everything is fine.</p>



<a name="196995853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/196995853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#196995853">(May 09 2020 at 15:05)</a>:</h4>
<p>If the libs team is fine with us adding the generic parameter, I would be in favour of that. It is the only feasible way that we can have people experiment with it on nightly. I feel like we will be going back and forth amongst each other trying to improve the <code>AllocRef</code> API; but the only way we'll really get any feedback is if people can actually easily start using the trait on common types, imo.</p>



<a name="197000159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197000159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197000159">(May 09 2020 at 16:37)</a>:</h4>
<p>I'd want to support such a thing. I'm working on stuff that really needs the allocator_api. I'm also working on my own standard library for a custom compiler, that would want to provide allocator aware collections/magic boxes. <br>
Having the support in the rust standard library, even behind unstable, would be nice to proceed with in my compiler/lib</p>



<a name="197001036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197001036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197001036">(May 09 2020 at 17:01)</a>:</h4>
<p>Could we have an unstable instance on <code>System</code>? I vaguely recall that being a thing</p>



<a name="197004110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197004110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197004110">(May 09 2020 at 18:06)</a>:</h4>
<blockquote>
<p>I'll double check the commits later or tomorrow, but I think everything is fine.</p>
</blockquote>
<p>Unfortunately I haven't been able to check this today, but will definitely review it again tomorrow. It would be frustrating, if a minor bug would lead to a major regression. There is enough time left to make a try-run before we got to the top of the crater queue.</p>



<a name="197004113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197004113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197004113">(May 09 2020 at 18:06)</a>:</h4>
<p>I would prefer just removing <code>AllocRef</code> on <code>System</code> for now so it isn't exposed to stable. I don't think it will be used much anyways.</p>



<a name="197004147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197004147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197004147">(May 09 2020 at 18:07)</a>:</h4>
<p>By the way the perf results show a pretty significant regression: <a href="https://perf.rust-lang.org/compare.html?start=97f3eeec8216d7155c24674b9be55e7c672bcae3&amp;end=ac6afa7e002222176f3dcb43f18522047891b080" title="https://perf.rust-lang.org/compare.html?start=97f3eeec8216d7155c24674b9be55e7c672bcae3&amp;end=ac6afa7e002222176f3dcb43f18522047891b080">https://perf.rust-lang.org/compare.html?start=97f3eeec8216d7155c24674b9be55e7c672bcae3&amp;end=ac6afa7e002222176f3dcb43f18522047891b080</a></p>



<a name="197004213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197004213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197004213">(May 09 2020 at 18:09)</a>:</h4>
<p>I think something in the generated code changed since the performance of -opt builds is affected.</p>



<a name="197050471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197050471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197050471">(May 10 2020 at 11:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/197181-t-libs.2Fwg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics/near/197004213" title="#narrow/stream/197181-t-libs.2Fwg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics/near/197004213">said</a>:</p>
<blockquote>
<p>I think something in the generated code changed since the performance of -opt builds is affected.</p>
</blockquote>
<p>Is there a good way to track down generated code changes?</p>



<a name="197051529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197051529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197051529">(May 10 2020 at 12:07)</a>:</h4>
<p>I reviewed my PR and didn't find anything which needs a fix (e.g. missing <code>= Global</code> or missing <code>#[unstable]</code>). The former should have been catched by the tests anyway. I changed the feature flag in <code>Box::new_uninit_slice_in</code> to <code>"allocator_api"</code> but this does not affect performance or the stable channel.</p>



<a name="197052555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/status%20of%20using%20the%20%60AllocRef%60%20trait%20%20in%20generics/near/197052555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/status.20of.20using.20the.20.60AllocRef.60.20trait.20.20in.20generics.html#197052555">(May 10 2020 at 12:27)</a>:</h4>
<p>In theory the monomoprhized code should be absolutely identical since all uses of <code>Box</code>/<code>Vec</code> should resolve the the same <code>Box&lt;T, Global&gt;</code> that it did before.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>